package com.chilli.cosima.action.providermanager;

import java.util.List;
import java.util.Map;

import com.chilli.cosima.action.BaseSupport;
import com.chilli.cosima.data.bean.Provider;
import com.chilli.cosima.service.ProviderService;

public class ProviderQueryAction extends BaseSupport
{

	private static final long serialVersionUID = -8162288485054844660L;

	private ProviderService providerService;

	private Integer id;

	private Provider provider;

	public String detail()
	{

		Provider provider = providerService.findProviderById(id);

		if (null != provider)
		{
			this.provider = provider;
			return DETAIL;
		} else
		{
			logger.error("error");
			return ERROR;
		}

	}

	@SuppressWarnings("unchecked")
	public String execute()
	{

		String page = request.getParameter("page");
		int current = 0;
		if (page != null && !"".equals(page))
		{
			current = Integer.parseInt(page);
		}

		Map map = providerService.findProviderByPage(current, pageSize);
		List list = (List) map.get("list");
		int count = (Integer) map.get("count");

		setPager(list, "provider/providerQueryAction.action", count);

		return SUCCESS;
	}

	public ProviderService getProviderService()
	{
		return providerService;
	}

	public void setProviderService(ProviderService providerService)
	{
		this.providerService = providerService;
	}

	public Integer getId()
	{
		return id;
	}

	public void setId(Integer id)
	{
		this.id = id;
	}

	public Provider getProvider()
	{
		return provider;
	}

	public void setProvider(Provider provider)
	{
		this.provider = provider;
	}

}
